#lang r5rs
(define (acc combiner null-value fun a next b)
  (define  (acc-iter combiner fun a next b result)
    (if (> a b)
        result
        (acc-iter combiner fun (next a) next b (combiner result (fun a)))))
  (acc-iter combiner fun a next b null-value))
(define (sum fun a b next) (acc + 0 fun a next b))

(define (product fun a b next) (acc * 1 fun a next b))

(define (fact n)
  (product (lambda (x) x) 1 n (lambda (x) (+ 1 x))))

(display (fact 5))